package com.branches.filters;

import java.io.FileFilter;
import java.util.ArrayList;
import java.util.List;

/**
 * @author wujian
 * @date 2024/5/18
 */
public class Test {
    public static void main(String[] args) {
        List<Integer> numbers = new ArrayList<>();
        for(int i = 0; i < 10; i++) {
            numbers.add(i);
        }
        numbers = filter(numbers, (Integer v) -> v % 2 == 0);
        System.out.println(numbers.size());

    }

    public static <T> List<T> filter(List<T> list, Predicate<T> p) {
        List<T> result = new ArrayList<>();
        for(T e: list){
            if(p.accept(e)) {
                result.add(e);
            }
        }
        return result;
    }
}
